"use strict";

var goodsID = location.href.match(/\/id\/(\d+)/)[1];
var zhengxinBox = $(".zhengxin_check_box");
var zhengxinYuqiBox = $(".yuqi_check_box");

$(document).ready(function() {
  var compentName = "x-zhengxin";
  var addZhengxinURL = String($("#post_new_zhengxin_require").val());
  var addZhengxinYuqiURL = String($("#post_new_zhengxin_yuqi_require").val());
  // const removeZhengxinURL = String($('#post_remove_zhengxin_require').val())
  // const removeZhengxinYuqiURL = String($('#post_remove_zhengxin_yuqi_require').val())
  var updataZhengxinURL = String($("#post_updata_zhengxin_require").val());
  var updataZhengxinYuqiURL = String(
    $("#post_updata_zhengxin_yuqi_require").val()
  );

  var URLObject = {
    addZhengxinURL: addZhengxinURL,
    addZhengxinYuqiURL: addZhengxinYuqiURL,
    // removeZhengxinURL: removeZhengxinURL,
    // removeZhengxinYuqiURL: removeZhengxinYuqiURL,
    updataZhengxinURL: updataZhengxinURL,
    updataZhengxinYuqiURL: updataZhengxinYuqiURL
    // 建立添加item的listener
  };
  $(".add_more_zhengxin_item").on(
    { click: addMoreZhengxinItem },
    { url: URLObject }
  );
  $(".add_more_yuqi_item").on({ click: addMoreYuqiItem }, { url: URLObject });
  // 初始化颜色选择
  $(".zhengxin_check_color").each(function(index, item) {
    $(item).colorPicker();
  });
  // 回填征信
  try {
    rewriteZhengxin();
  } catch (err) {
    console.log(err);
  }
  try {
    rewriteZhengxinYuqi();
  } catch (err) {
    console.log(err);
  }
  // 初始化征信
  $("#zhengxin_check_if").one("change", function(event) {
    if (
      $(event.target)
        .closest(".zhengxin_check_line")
        .find(".zhengxin_check_line_id").length > 0
    ) {
      throw new Error("log: 存在征信消息id，判断已经有回填，不需要进行初始化请求");
    }
    var goodsID = location.href.match(/\/id\/(\d+)/)[1];
    var addZhengxinURL = String($("#post_new_zhengxin_require").val());
    console.log("请求一行新的征信要求，发送：");
    var postData = {
      zhengxin_check_if: "",
      zhengxin_check_count_method: "",
      zhengxin_check_count_cycle: "",
      zhengxin_check_count_time: "",
      cinv_times_color: "",
      g_id: goodsID,
      state: 1
    };
    console.dir(postData);
    $.ajax(addZhengxinURL, {
      method: "post",
      data: postData
    })
      .done(function(data) {
        if (String(data.code) === "1" || String(data.code) === "2") {
          // 请求成功
          var templ = ('\n          <input type="num" name="zhengxin_check_count_cycle" id="zhengxin_check_count_cycle" placeholder="1~36\u4E2A\u6708"/>\n          <div class="placeholder">\u4E0D\u80FD\u8D85\u8FC7</div>\n          <select name="zhengxin_check_count_time" id="zhengxin_check_count_time">\n            <option value="1" checked>1\u6B21</option>\n            <option value="2">2\u6B21</option>\n            <option value="3">3\u6B21</option>\n            <option value="4">4\u6B21</option>\n            <option value="5">5\u6B21</option>\n            <option value="6">6\u6B21</option>\n            <option value="7">7\u6B21</option>\n            <option value="8">8\u6B21</option>\n            <option value="9">9\u6B21</option>\n            <option value="10">10\u6B21</option>\n            <option value="11">11\u6B21</option>\n            <option value="12">12\u6B21</option>\n            <option value="13">13\u6B21</option>\n            <option value="14">14\u6B21</option>\n            <option value="15">15\u6B21</option>\n            <option value="16">16\u6B21</option>\n            <option value="17">17\u6B21</option>\n            <option value="18">18\u6B21</option>\n            <option value="19">19\u6B21</option>\n            <option value="20">20\u6B21\u6216\u4EE5\u4E0A</option>\n          </select>\n          <div class="add_more_zhengxin_item"><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u546.png" alt="u546"></div>\n          <input type="hidden" class="zhengxin_check_line_id" name="zhengxin_check_line_id" value=\'' +
            data.cinv_times_id +
            "'>\n          <input form='hidden_color_placeholder' class='zhengxin_check_color' id=\"zhengxin_check_1\" type=\"hidden\" name=\"color\" value=\"#000\" />\n          <script>\n            const addZhengxinURL = String($('#post_new_zhengxin_require').val())\n            $('#zhengxin_check_1').colorPicker()\n            $('.add_more_zhengxin_item').on({click: addMoreZhengxinItem}, {\n              url: {\n                addZhengxinURL: addZhengxinURL,\n              }\n            })\n          </script>\n        ").trim();
          $(".zhengxin_check_line").append(templ);
        } else {
          // 请求无法完成
          console.log(data);
        }
      })
      .fail(function(err) {
        // 网络错误
        console.log(err);
      });
  });
  // 初始化征信逾期
  $("#yuqi_check_if").one("change", function(event) {
    if (
      $(event.target)
        .closest(".yuqi_check_line")
        .find(".yuqi_check_line_id").length > 0
    ) {
      throw new Error("log: 存在征信逾期消息id，判断已经有回填，不需要进行初始化请求");
    }
    var goodsID = location.href.match(/\/id\/(\d+)/)[1];
    var addZhengxinURL = String($("#post_new_zhengxin_yuqi_require").val());
    console.log("请求一行新的征信逾期要求，发送：");
    var postData = {
      yuqi_check_if: "",
      yuqi_check_count_method: "",
      yuqi_check_count_cycle: "",
      yuqi_check_count_time: "",
      yuqi_check_count_source: "",
      cinv_times_color: "",
      g_id: goodsID,
      state: 1
    };
    console.dir(postData);
    $.ajax(addZhengxinURL, {
      method: "post",
      data: postData
    })
      .done(function(data) {
        if (String(data.code) === "1" || String(data.code) === "2") {
          // 请求成功
          var templ = ('\n          <input type="num" name="yuqi_check_count_cycle" id="yuqi_check_count_cycle" placeholder="1~36\u4E2A\u6708"/>\n          <div class="placeholder">\u4E0D\u80FD</div>\n          <select name="yuqi_check_count_method" id="yuqi_check_count_method">\n            <option value="\u8FDE\u7EED">\u8FDE\u7EED</option>\n            <option value="\u7D2F\u8BA1">\u7D2F\u8BA1</option>\n          </select>\n          <select name="yuqi_check_count_time" id="yuqi_check_count_time">\n            <option value="1" checked>1\u4E2A</option>\n            <option value="2">2\u4E2A</option>\n            <option value="3">3\u4E2A</option>\n            <option value="4">4\u4E2A</option>\n            <option value="5">5\u4E2A</option>\n            <option value="6">6\u4E2A</option>\n            <option value="7">7\u4E2A</option>\n            <option value="8">8\u4E2A</option>\n            <option value="9">9\u4E2A</option>\n            <option value="10">10\u4E2A</option>\n            <option value="11">11\u4E2A</option>\n            <option value="12">12\u4E2A</option>\n            <option value="13">13\u4E2A</option>\n            <option value="14">14\u4E2A</option>\n            <option value="15">15\u4E2A</option>\n            <option value="16">16\u4E2A</option>\n            <option value="17">17\u4E2A</option>\n            <option value="18">18\u4E2A</option>\n            <option value="19">19\u4E2A</option>\n            <option value="20">20\u4E2A</option>\n          </select>\n          <select name="yuqi_check_count_source" id="yuqi_check_count_source">\n            <option value="1" checked>1</option>\n            <option value="2">2</option>\n            <option value="3">3</option>\n            <option value="4">4</option>\n            <option value="5">5</option>\n            <option value="6">6</option>\n            <option value="7">7</option>\n          </select>\n          <div class="add_more_yuqi_item"><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u546.png" alt="u546"></div>\n          <input type="hidden" class="yuqi_check_line_id" name="yuqi_check_line_id" value=\'' +
            data.cinv_see_id +
            "'>\n          <input form='hidden_color_placeholder' class='zhengxin_check_color' id=\"yuqi_check_1\" type=\"hidden\" name=\"color\" value=\"#000\" />\n          <script>\n            const addZhengxinYuqiURL = String($('#post_new_zhengxin_yuqi_require').val())\n            const URLObject = {\n              addZhengxinYuqiURL: addZhengxinYuqiURL,\n            }\n            $('#yuqi_check_1').colorPicker()\n            $('.add_more_yuqi_item').on({click: addMoreYuqiItem}, {url: URLObject})\n          </script>\n        ").trim();
          $(".yuqi_check_line").append(templ);
        } else {
          // 请求无法完成
          console.log(data);
        }
      })
      .fail(function(err) {
        // 网络错误
        console.log(err);
      });
  });
  // 征信逾期在选择为不显示时，隐藏右边的
  $("#zhengxin_check_if").on("change", function(evt) {
    if (String($(evt.target).val()) === "0") {
      $(".zhengxin_check_line").each(function(index, item) {
        if (index === 0) {
          // 第一行留下第一个
          $(item)
            .children("div,input,select")
            .each(function(subindex, subitem) {
              if (subindex > 1) {
                $(subitem).css("display", "none");
              }
            });
        } else {
          $(item).css("display", "none");
        }
      });
    } else {
      $(".zhengxin_check_line").each(function(index, item) {
        if (index === 0) {
          // 第一行留下第一个
          $(item)
            .children("div,input,select")
            .each(function(subindex, subitem) {
              if (subindex > 1) {
                $(subitem).css("display", "block");
              }
            });
        } else {
          $(item).css("display", "flex");
        }
      });
    }
  });
  $("#yuqi_check_if").on("change", function(evt) {
    if (String($(evt.target).val()) === "0") {
      $(".yuqi_check_line").each(function(index, item) {
        if (index === 0) {
          // 第一行留下第一个
          $(item)
            .children("div,input,select")
            .each(function(subindex, subitem) {
              if (subindex > 0) {
                $(subitem).css("display", "none");
              }
            });
        } else {
          $(item).css("display", "none");
        }
      });
    } else {
      $(".yuqi_check_line").each(function(index, item) {
        if (index === 0) {
          // 第一行留下第一个
          $(item)
            .children("div,input,select")
            .each(function(subindex, subitem) {
              if (subindex > 0) {
                $(subitem).css("display", "block");
              }
            });
        } else {
          $(item).css("display", "flex");
        }
      });
    }
  });
});

function addMoreZhengxinItem(evt) {
  console.log("请求一行新的征信要求，发送：");
  var postData = {
    zhengxin_check_if: $("#zhengxin_check_if").val(),
    zhengxin_check_count_method: $("#zhengxin_check_count_method").val(),
    zhengxin_check_count_cycle: $("#zhengxin_check_count_cycle").val(),
    zhengxin_check_count_time: $("#zhengxin_check_count_time").val(),
    cinv_times_color: $("#zhengxin_check_1").val(),
    g_id: goodsID,
    state: $(".zhengxin_check_line").length === 1 ? 1 : 0
    // const postData = $('#zhengxin_hidden_form').serializeArray()
  };
  console.dir(postData);
  // throw new Error(`1`)
  $.ajax(evt.data.url.addZhengxinURL, {
    method: "post",
    data: postData,
    beforeSend: function beforeSend() {
      $(".add_more_zhengxin_item").css("display", "none");
    }
  })
    .done(function(data) {
      $(".add_more_zhengxin_item").css("display", "block");
      if (String(data.code) === "1" || String(data.code) === "2") {
        // 请求成功
        var templ = ('\n        <div class="zhengxin_check_line">\n          <div style="width:27.5rem;"></div>\n          <input type="num" id=\'zhengxin_check_count_cycle_' +
          data.cinv_times_id +
          '\' name="zhengxin_check_count_cycle" placeholder="1~36\u4E2A\u6708"/>\n          <div class="placeholder">\u4E0D\u80FD\u8D85\u8FC7</div>\n          <select name="zhengxin_check_count_time" id=\'zhengxin_check_count_time_' +
          data.cinv_times_id +
          '\'>\n            <option value="1">1\u6B21</option>\n            <option value="2">2\u6B21</option>\n            <option value="3">3\u6B21</option>\n            <option value="4">4\u6B21</option>\n            <option value="5">5\u6B21</option>\n            <option value="6">6\u6B21</option>\n            <option value="7">7\u6B21</option>\n            <option value="8">8\u6B21</option>\n            <option value="9">9\u6B21</option>\n            <option value="10">10\u6B21</option>\n            <option value="11">11\u6B21</option>\n            <option value="12">12\u6B21</option>\n            <option value="13">13\u6B21</option>\n            <option value="14">14\u6B21</option>\n            <option value="15">15\u6B21</option>\n            <option value="16">16\u6B21</option>\n            <option value="17">17\u6B21</option>\n            <option value="18">18\u6B21</option>\n            <option value="19">19\u6B21</option>\n            <option value="20">20\u6B21\u6216\u4EE5\u4E0A</option>\n          </select>\n          <div class="deleteThisLine" onclick=\'deleteThisZhengxin(this, event)\'><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u566.png" alt="u566"></div>\n          <input type="hidden" id=\'zhengxin_check_line_id_' +
          data.cinv_times_id +
          '\' class="zhengxin_check_line_id" name="zhengxin_check_line_id" value=\'' +
          data.cinv_times_id +
          "'>\n          <input form='hidden_color_placeholder' class='zhengxin_check_color' id=\"zhengxin_check_" +
          data.cinv_times_id +
          '" type="hidden" name="color" value="" />\n        </div>\n        <script>\n          $(\'#zhengxin_check_' +
          data.cinv_times_id +
          "').colorPicker()\n        </script>\n      ").trim();
        $(".zhengxin_check_box").append(templ);
      } else {
        // 请求无法完成
        console.log(data);
      }
    })
    .fail(function(err) {
      // 网络错误
      console.log(err);
    });
}
function addMoreYuqiItem(evt) {
  console.log("请求一行新的征信逾期要求，发送：");
  var postData = {
    yuqi_check_if: $("#yuqi_check_if").val(),
    yuqi_check_count_method: $("#yuqi_check_count_method").val(),
    yuqi_check_count_cycle: $("#yuqi_ check_count_cycle").val(),
    yuqi_check_count_time: $("#yuqi_check_count_time").val(),
    yuqi_check_count_source: $("#yuqi_check_count_source").val(),
    cinv_times_color: $("#yuqi_check_1").val(),
    g_id: goodsID,
    state: $(".yuqi_check_line").length === 1 ? 1 : 0
    // const postData = $('#zhengxin_hidden_form').serializeArray()
  };
  console.dir(postData);
  $.ajax(evt.data.url.addZhengxinYuqiURL, {
    method: "post",
    data: postData,
    beforeSend: function beforeSend() {
      $(".add_more_yuqi_item").css("display", "none");
    }
  }).done(function(data) {
    $(".add_more_yuqi_item").css("display", "block");
    if (String(data.code) === "1" || String(data.code) === "2") {
      var templ = ('\n        <div class="yuqi_check_line">\n          <div style="width:13.5rem;"></div>\n          <input type="num" name="yuqi_check_count_cycle" id=\'yuqi_check_count_cycle_' +
        data.cinv_see_id +
        '\' placeholder="1~36\u4E2A\u6708"/>\n          <div class="placeholder">\u4E0D\u80FD</div>\n          <select name="yuqi_check_count_method" id=\'yuqi_check_count_method_' +
        data.cinv_see_id +
        '\'>\n            <option value="\u8FDE\u7EED">\u8FDE\u7EED</option>\n            <option value="\u7D2F\u8BA1">\u7D2F\u8BA1</option>\n          </select>\n          <select name="yuqi_check_count_time" id=\'yuqi_check_count_time_' +
        data.cinv_see_id +
        '\'>\n            <option value="1">1\u4E2A</option>\n            <option value="2">2\u4E2A</option>\n            <option value="3">3\u4E2A</option>\n            <option value="4">4\u4E2A</option>\n            <option value="5">5\u4E2A</option>\n            <option value="6">6\u4E2A</option>\n            <option value="7">7\u4E2A</option>\n            <option value="8">8\u4E2A</option>\n            <option value="9">9\u4E2A</option>\n            <option value="10">10\u4E2A</option>\n            <option value="11">11\u4E2A</option>\n            <option value="12">12\u4E2A</option>\n            <option value="13">13\u4E2A</option>\n            <option value="14">14\u4E2A</option>\n            <option value="15">15\u4E2A</option>\n            <option value="16">16\u4E2A</option>\n            <option value="17">17\u4E2A</option>\n            <option value="18">18\u4E2A</option>\n            <option value="19">19\u4E2A</option>\n            <option value="20">20\u4E2A</option>\n          </select>\n          <select name="yuqi_check_count_source" id=\'yuqi_check_count_source_' +
        data.cinv_see_id +
        '\'>\n            <option value="1">1</option>\n            <option value="2">2</option>\n            <option value="3">3</option>\n            <option value="4">4</option>\n            <option value="5">5</option>\n            <option value="6">6</option>\n            <option value="7">7</option>\n          </select>\n          <div class="deleteThisLine" onclick=\'deleteThisYuqi(this, event)\'><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u566.png" alt="u566"></div>\n          <input type="hidden" class="yuqi_check_line_id" id=\'yuqi_check_line_id_' +
        data.cinv_see_id +
        "' name=\"yuqi_check_line_id\" value='" +
        data.cinv_see_id +
        "'>\n          <input form='hidden_color_placeholder' class='zhengxin_check_color' id=\"yuqi_check_" +
        data.cinv_see_id +
        '" type="hidden" name="color" value="#000" />\n        </div>\n        <script>\n          $(\'#yuqi_check_' +
        data.cinv_see_id +
        "').colorPicker()\n        </script>\n      ").trim();
      $(".yuqi_check_box").append(templ);
    } else {
      console.log(data);
    }
  });
}
function deleteThisYuqi(_this, evt) {
  var parentEle = $(evt.target).closest(".yuqi_check_line");
  var lineID = parentEle.find(".yuqi_check_line_id").val();
  console.log("请求删除一行征信逾期要求，发送：");
  console.log("{cinv_see_id: " + lineID + "}");
  $.ajax(String($("#post_remove_zhengxin_yuqi_require").val()), {
    method: "post",
    data: { cinv_see_id: lineID }
  })
    .done(function(data) {
      if (String(data.code) === "1" || String(data.code) === "2") {
        parentEle.remove();
      } else {
        console.log(data);
      }
    })
    .fail(function(err) {
      console.log(err);
    });
}
function deleteThisZhengxin(_this, evt) {
  var parentEle = $(evt.target).closest(".zhengxin_check_line");
  var lineID = parentEle.find(".zhengxin_check_line_id").val();
  console.log("请求删除一行征信要求，发送：");
  console.log("{cinv_times_id: " + lineID + "}");
  $.ajax(String($("#post_remove_zhengxin_require").val()), {
    method: "post",
    data: { cinv_times_id: lineID }
  })
    .done(function(data) {
      if (String(data.code) === "1" || String(data.code) === "2") {
        parentEle.remove();
      } else {
        console.log(data);
      }
    })
    .fail(function(err) {
      console.log(err);
    });
}

function submitZhengxin() {
  var postData = [];
  var allLineEle = $(".zhengxin_check_line");
  allLineEle.find("input").each(function(index, item) {
    var value = String($(item).val()).replace(/[\D]/, "");
    if (value === "") {
      alert("征信表单未填写完毕");
      throw new Error("征信表单未填写完毕");
    }
    if (
      $(item).attr("type") === "num" &&
      (Number(value) < 1 || Number(value) > 36)
    ) {
      alert("征信表单未正确填写完毕");
      throw new Error("征信表单未正确填写完毕");
    }
  });
  allLineEle.each(function(index, item) {
    if (index === 0) {
      var ID = $(item)
        .find(".zhengxin_check_line_id")
        .val();
      var itemData = {
        zhengxin_check_if: $("#zhengxin_check_if").val(),
        // 数组转字符串，多选下拉
        zhengxin_check_count_method: Array.from(
          $("#zhengxin_check_count_method").val()
        ).join(","),
        zhengxin_check_count_cycle: $("#zhengxin_check_count_cycle").val(),
        zhengxin_check_count_time: $("#zhengxin_check_count_time").val(),
        cinv_times_color: $("#zhengxin_check_1").val(),
        g_id: goodsID,
        cinv_times_id: ID,
        state: 1
      };
      postData.push(itemData);
    } else {
      var _ID = $(item)
        .find(".zhengxin_check_line_id")
        .val();
      var _itemData = {
        zhengxin_check_if: $("#zhengxin_check_if").val(),
        zhengxin_check_count_method: Array.from(
          $("#zhengxin_check_count_method").val()
        ).join(","),
        zhengxin_check_count_cycle: $(
          "#zhengxin_check_count_cycle_" + _ID
        ).val(),
        zhengxin_check_count_time: $("#zhengxin_check_count_time_" + _ID).val(),
        cinv_times_color: $("#zhengxin_check_" + _ID).val(),
        g_id: goodsID,
        cinv_times_id: _ID,
        state: 0
      };
      postData.push(_itemData);
    }
  });
  console.dir(JSON.parse(JSON.stringify(postData)));
  $.ajax(String($("#post_updata_zhengxin_require").val()), {
    method: "post",
    data: { data: postData },
    async: false
  })
    .done(function(data) {
      if (String(data.code) === "1" || String(data.code) === "2") {
        console.log(data);
      } else {
        console.log(data);
        alert("服务器无法接受信息");
        throw new Error("服务器无法接受信息");
      }
    })
    .fail(function(err) {
      console.log(err);
      alert("无法提交征信信息");
      throw err;
    });
}

function submtZhengxinYuqi() {
  var postData = [];
  var allLineEle = $(".yuqi_check_line");
  allLineEle.find("input").each(function(index, item) {
    var value = String($(item).val()).replace(/\D/, "");
    if (value === "") {
      alert("征信表单未填写完毕");
      throw new Error("征信表单未填写完毕");
    }
    if (
      $(item).attr("type") === "num" &&
      (Number(value) < 1 || Number(value) > 36)
    ) {
      alert("征信表单未正确填写完毕");
      throw new Error("征信表单未正确填写完毕");
    }
  });
  allLineEle.each(function(index, item) {
    if (index === 0) {
      var ID = $(item)
        .find(".yuqi_check_line_id")
        .val();
      var itemData = {
        cinv_see_id: ID,
        yuqi_check_if: $("#yuqi_check_if").val(),
        yuqi_check_count_method: $("#yuqi_check_count_method").val(),
        yuqi_check_count_cycle: $("#yuqi_check_count_cycle").val(),
        yuqi_check_count_time: $("#yuqi_check_count_time").val(),
        yuqi_check_count_source: $("#yuqi_check_count_source").val(),
        cinv_see_color: $("#yuqi_check_1").val(),
        g_id: goodsID,
        state: 1
      };
      postData.push(itemData);
    } else {
      var _ID2 = $(item)
        .find(".yuqi_check_line_id")
        .val();
      var _itemData2 = {
        cinv_see_id: _ID2,
        yuqi_check_if: $("#yuqi_check_if").val(),
        yuqi_check_count_method: $("#yuqi_check_count_method_" + _ID2).val(),
        yuqi_check_count_cycle: $("#yuqi_check_count_cycle_" + _ID2).val(),
        yuqi_check_count_time: $("#yuqi_check_count_time_" + _ID2).val(),
        yuqi_check_count_source: $("#yuqi_check_count_source_" + _ID2).val(),
        cinv_see_color: $("#yuqi_check_" + _ID2).val(),
        g_id: goodsID,
        state: 0
      };
      postData.push(_itemData2);
    }
  });
  console.dir(postData);
  $.ajax(String($("#post_updata_zhengxin_yuqi_require").val()), {
    method: "post",
    data: { data: postData },
    async: false
  })
    .done(function(data) {
      if (String(data.code) === "1" || String(data.code) === "2") {
        console.log(data);
      } else {
        console.error("失败");
        alert("服务器无法接受信息");
        throw new Error("服务器无法接受信息");
      }
    })
    .fail(function(err) {
      alert("无法提交征信信息");
      throw new Error(err);
    });
}

function rewriteZhengxin() {
  if (window.altFormData.altFormDataZhengxin === "") {
    throw new Error(
      "\u4E0D\u5B58\u5728\u5F81\u4FE1\u56DE\u586B\u6570\u636E\uFF0C\u505C\u6B62\u56DE\u586B\u64CD\u4F5C"
    );
  }
  var templValue = JSON.parse(window.altFormData.altFormDataZhengxin);
  /**
   *
   * let altFormDataZhengxiYuqi = `[{"cinv_see_id":"7","yuqi_check_if":"1","yuqi_check_count_cycle":"2","yuqi_check_count_method":"\u7d2f\u8ba1","yuqi_check_count_time":"19","yuqi_check_count_source":"2","g_id":"25","state":"1","cinv_see_color":"#ff0000"},{"cinv_see_id":"8","yuqi_check_if":"1","yuqi_check_count_cycle":"33","yuqi_check_count_method":"\u7d2f\u8ba1","yuqi_check_count_time":"19","yuqi_check_count_source":"2","g_id":"25","state":"0","cinv_see_color":"#808000"}]`;
   * let altFormDataZhengxin = `[{"cinv_times_id":"7","zhengxin_check_if":"1","zhengxin_check_count_method":"\u4fe1\u7528\u5361\u67e5\u8be2","zhengxin_check_count_cycle":"1","zhengxin_check_count_time":"18","cinv_times_color":"#ff6600","g_id":"25","state":"1"},{"cinv_times_id":"8","zhengxin_check_if":"1","zhengxin_check_count_method":"\u4fe1\u7528\u5361\u67e5\u8be2","zhengxin_check_count_cycle":"22","zhengxin_check_count_time":"18","cinv_times_color":"#800080","g_id":"25","state":"0"}]`;
   * window.altFormData = {
   *   altFormDataZhengxin: altFormDataZhengxin,
   *   altFormDataZhengxiYuqi: altFormDataZhengxiYuqi
   * }
   */
  $.each(templValue, function(index, item) {
    if (index === 0) {
      var firstLineTempl = ('\n        <div class="zhengxin_check_box">\n          <div class="zhengxin_check_line">\n            <select name="zhengxin_check_if" id="zhengxin_check_if">\n              <option value="0">\u4E0D\u770B\u67E5\u8BE2\u6B21\u6570</option>\n              <option value="1">\u770B\u67E5\u8BE2\u6B21\u6570</option>\n            </select>\n            <div class="zhengxin_check_count_method_wrap">\n              <label for="x_zhengxin_zhengxin_check_count_method">\n                <div>\u67E5\u8BE2\u8BA1\u7B97\u6807\u51C6<br>(ctrl\u952E\u53EF\u591A\u9009)</div>\n              </label>\n              <input style=\'display:none;\' type="checkbox" name="\u8C03\u6574\u662F\u5426\u663E\u793A" id=\'x_zhengxin_zhengxin_check_count_method\'>\n              <select name="zhengxin_check_count_method" id="zhengxin_check_count_method" multiple>\n                <option value="\u8D37\u6B3E\u7533\u8BF7" checked>\u8D37\u6B3E\u7533\u8BF7</option>\n                <option value="\u4FE1\u7528\u5361\u67E5\u8BE2">\u4FE1\u7528\u5361\u67E5\u8BE2</option>\n                <option value="\u4E2A\u4EBA\u67E5\u8BE2">\u4E2A\u4EBA\u67E5\u8BE2</option>\n                <option value="\u4FDD\u524D\u5BA1\u6279">\u4FDD\u524D\u5BA1\u6279</option>\n              </select>\n            </div>\n            <input type="num" name="zhengxin_check_count_cycle" id="zhengxin_check_count_cycle" placeholder="1~36\u4E2A\u6708"/>\n            <div class="placeholder">\u4E0D\u80FD\u8D85\u8FC7</div>\n            <select name="zhengxin_check_count_time" id="zhengxin_check_count_time">\n              <option value="1" checked>1\u6B21</option>\n              <option value="2">2\u6B21</option>\n              <option value="3">3\u6B21</option>\n              <option value="4">4\u6B21</option>\n              <option value="5">5\u6B21</option>\n              <option value="6">6\u6B21</option>\n              <option value="7">7\u6B21</option>\n              <option value="8">8\u6B21</option>\n              <option value="9">9\u6B21</option>\n              <option value="10">10\u6B21</option>\n              <option value="11">11\u6B21</option>\n              <option value="12">12\u6B21</option>\n              <option value="13">13\u6B21</option>\n              <option value="14">14\u6B21</option>\n              <option value="15">15\u6B21</option>\n              <option value="16">16\u6B21</option>\n              <option value="17">17\u6B21</option>\n              <option value="18">18\u6B21</option>\n              <option value="19">19\u6B21</option>\n              <option value="20">20\u6B21\u6216\u4EE5\u4E0A</option>\n            </select>\n            <div class="add_more_zhengxin_item"><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u546.png" alt="u546"></div>\n            <input type="hidden" class="zhengxin_check_line_id" name="zhengxin_check_line_id" value=\'' +
        item.cinv_times_id +
        '\'>\n            <input form=\'hidden_color_placeholder\' class=\'zhengxin_check_color\' id="zhengxin_check_1" type="hidden" name="color" value="' +
        item.cinv_times_color +
        "\" />\n            <script>\n              const addZhengxinURL = String($('#post_new_zhengxin_require').val())\n              $('#zhengxin_check_1').colorPicker()\n              $('.add_more_zhengxin_item').on({click: addMoreZhengxinItem}, {\n                url: {\n                  addZhengxinURL: addZhengxinURL,\n                }\n              })\n              $('#zhengxin_check_if').val('" +
        item.zhengxin_check_if +
        "')\n              $('#zhengxin_check_count_method').val('" +
        item.zhengxin_check_count_method +
        "'.split(','))\n              $('#zhengxin_check_count_time').val('" +
        item.zhengxin_check_count_time +
        "')\n              $('#zhengxin_check_count_cycle').val('" +
        item.zhengxin_check_count_cycle +
        "')\n            </script>\n          </div>\n        </div>\n      ").trim();
      $(".zhengxin_check_box").replaceWith(firstLineTempl);
    } else {
      var templ = ('\n        <div class="zhengxin_check_line">\n          <div style="width:27.5rem;"></div>\n          <input type="num" id=\'zhengxin_check_count_cycle_' +
        item.cinv_times_id +
        '\' name="zhengxin_check_count_cycle" placeholder="1~36\u4E2A\u6708"/>\n          <div class="placeholder">\u4E0D\u80FD\u8D85\u8FC7</div>\n          <select name="zhengxin_check_count_time" id=\'zhengxin_check_count_time_' +
        item.cinv_times_id +
        '\'>\n            <option value="1">1\u6B21</option>\n            <option value="2">2\u6B21</option>\n            <option value="3">3\u6B21</option>\n            <option value="4">4\u6B21</option>\n            <option value="5">5\u6B21</option>\n            <option value="6">6\u6B21</option>\n            <option value="7">7\u6B21</option>\n            <option value="8">8\u6B21</option>\n            <option value="9">9\u6B21</option>\n            <option value="10">10\u6B21</option>\n            <option value="11">11\u6B21</option>\n            <option value="12">12\u6B21</option>\n            <option value="13">13\u6B21</option>\n            <option value="14">14\u6B21</option>\n            <option value="15">15\u6B21</option>\n            <option value="16">16\u6B21</option>\n            <option value="17">17\u6B21</option>\n            <option value="18">18\u6B21</option>\n            <option value="19">19\u6B21</option>\n            <option value="20">20\u6B21\u6216\u4EE5\u4E0A</option>\n          </select>\n          <div class="deleteThisLine" onclick=\'deleteThisZhengxin(this, event)\'><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u566.png" alt="u566"></div>\n          <input type="hidden" id=\'zhengxin_check_line_id_' +
        item.cinv_times_id +
        '\' class="zhengxin_check_line_id" name="zhengxin_check_line_id" value=\'' +
        item.cinv_times_id +
        "'>\n          <input form='hidden_color_placeholder' class='zhengxin_check_color' id=\"zhengxin_check_" +
        item.cinv_times_id +
        '" type="hidden" name="color" value="' +
        item.cinv_times_color +
        "\" />\n        </div>\n        <script>\n          $('#zhengxin_check_" +
        item.cinv_times_id +
        "').colorPicker()\n          $('#zhengxin_check_count_time_" +
        item.cinv_times_id +
        "').val('" +
        item.zhengxin_check_count_time +
        "')\n          $('#zhengxin_check_count_cycle_" +
        item.cinv_times_id +
        "').val('" +
        item.zhengxin_check_count_cycle +
        "')\n        </script>\n      ").trim();
      $(".zhengxin_check_box").append(templ);
    }
  });
}

function rewriteZhengxinYuqi() {
  if (window.altFormData.altFormDataZhengxiYuqi === "") {
    throw new Error(
      "\u4E0D\u5B58\u5728\u5F81\u4FE1\u903E\u671F\u56DE\u586B\u6570\u636E\uFF0C\u505C\u6B62\u56DE\u586B\u64CD\u4F5C"
    );
  }
  var templValue = JSON.parse(window.altFormData.altFormDataZhengxiYuqi);
  $.each(templValue, function(index, item) {
    if (index === 0) {
      var ramdom = ~~(Math.random() * 1e5);
      var firstLineTempl = ('\n        <div class="yuqi_check_box">\n          <div class="yuqi_check_line">\n            <select name="yuqi_check_if" id="yuqi_check_if">\n              <option value="0" checked>\u4E0D\u770B\u4EBA\u884C\u5F81\u4FE1</option>\n              <option value="1">\u770B\u4EBA\u884C\u5F81\u4FE1</option>\n            </select>\n            <input type="num" name="yuqi_check_count_cycle" id="yuqi_check_count_cycle" placeholder="1~36\u4E2A\u6708"/>\n            <div class="placeholder">\u4E0D\u80FD</div>\n            <select name="yuqi_check_count_method" id="yuqi_check_count_method">\n              <option value="\u8FDE\u7EED">\u8FDE\u7EED</option>\n              <option value="\u7D2F\u8BA1">\u7D2F\u8BA1</option>\n            </select>\n            <select name="yuqi_check_count_time" id="yuqi_check_count_time">\n              <option value="1" checked>1\u4E2A</option>\n              <option value="2">2\u4E2A</option>\n              <option value="3">3\u4E2A</option>\n              <option value="4">4\u4E2A</option>\n              <option value="5">5\u4E2A</option>\n              <option value="6">6\u4E2A</option>\n              <option value="7">7\u4E2A</option>\n              <option value="8">8\u4E2A</option>\n              <option value="9">9\u4E2A</option>\n              <option value="10">10\u4E2A</option>\n              <option value="11">11\u4E2A</option>\n              <option value="12">12\u4E2A</option>\n              <option value="13">13\u4E2A</option>\n              <option value="14">14\u4E2A</option>\n              <option value="15">15\u4E2A</option>\n              <option value="16">16\u4E2A</option>\n              <option value="17">17\u4E2A</option>\n              <option value="18">18\u4E2A</option>\n              <option value="19">19\u4E2A</option>\n              <option value="20">20\u4E2A</option>\n            </select>\n            <select name="yuqi_check_count_source" id="yuqi_check_count_source">\n              <option value="1" checked>1</option>\n              <option value="2">2</option>\n              <option value="3">3</option>\n              <option value="4">4</option>\n              <option value="5">5</option>\n              <option value="6">6</option>\n              <option value="7">7</option>\n            </select>\n            <div class="add_more_yuqi_item"><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u546.png" alt="u546"></div>\n            <input type="hidden" class="yuqi_check_line_id" name="yuqi_check_line_id" value=\'' +
        item.cinv_see_id +
        '\'>\n            <input form=\'hidden_color_placeholder\' class=\'zhengxin_check_color\' id="yuqi_check_1" type="hidden" name="color" value="' +
        item.cinv_see_color +
        '" />\n            <script>\n\n              const addZhengxinYuqiURL' +
        ramdom +
        " = String($('#post_new_zhengxin_yuqi_require').val())\n              const URLObject" +
        ramdom +
        " = {\n                addZhengxinYuqiURL: addZhengxinYuqiURL" +
        ramdom +
        ",\n              }\n              $('#yuqi_check_1').colorPicker()\n              $('.add_more_yuqi_item').on({click: addMoreYuqiItem}, {url: URLObject" +
        ramdom +
        "})\n              $('#yuqi_check_if').val('" +
        item.yuqi_check_if +
        "')\n              $('#yuqi_check_count_cycle').val('" +
        item.yuqi_check_count_cycle +
        "')\n              $('#yuqi_check_count_method').val('" +
        item.yuqi_check_count_method +
        "')\n              $('#yuqi_check_count_time').val('" +
        item.yuqi_check_count_time +
        "')\n              $('#yuqi_check_count_source').val('" +
        item.yuqi_check_count_source +
        "')\n            </script>\n          </div>\n        </div>\n      ").trim();
      $(".yuqi_check_box").replaceWith(firstLineTempl);
    } else {
      var templ = ('\n        <div class="yuqi_check_line">\n          <div style="width:13.5rem;"></div>\n          <input type="num" name="yuqi_check_count_cycle" id=\'yuqi_check_count_cycle_' +
        item.cinv_see_id +
        '\' placeholder="1~36\u4E2A\u6708"/>\n          <div class="placeholder">\u4E0D\u80FD</div>\n          <select name="yuqi_check_count_method" id=\'yuqi_check_count_method_' +
        item.cinv_see_id +
        '\'>\n            <option value="\u8FDE\u7EED">\u8FDE\u7EED</option>\n            <option value="\u7D2F\u8BA1">\u7D2F\u8BA1</option>\n          </select>\n          <select name="yuqi_check_count_time" id=\'yuqi_check_count_time_' +
        item.cinv_see_id +
        '\'>\n            <option value="1">1\u4E2A</option>\n            <option value="2">2\u4E2A</option>\n            <option value="3">3\u4E2A</option>\n            <option value="4">4\u4E2A</option>\n            <option value="5">5\u4E2A</option>\n            <option value="6">6\u4E2A</option>\n            <option value="7">7\u4E2A</option>\n            <option value="8">8\u4E2A</option>\n            <option value="9">9\u4E2A</option>\n            <option value="10">10\u4E2A</option>\n            <option value="11">11\u4E2A</option>\n            <option value="12">12\u4E2A</option>\n            <option value="13">13\u4E2A</option>\n            <option value="14">14\u4E2A</option>\n            <option value="15">15\u4E2A</option>\n            <option value="16">16\u4E2A</option>\n            <option value="17">17\u4E2A</option>\n            <option value="18">18\u4E2A</option>\n            <option value="19">19\u4E2A</option>\n            <option value="20">20\u4E2A</option>\n          </select>\n          <select name="yuqi_check_count_source" id=\'yuqi_check_count_source_' +
        item.cinv_see_id +
        '\'>\n            <option value="1">1</option>\n            <option value="2">2</option>\n            <option value="3">3</option>\n            <option value="4">4</option>\n            <option value="5">5</option>\n            <option value="6">6</option>\n            <option value="7">7</option>\n          </select>\n          <div class="deleteThisLine" onclick=\'deleteThisYuqi(this, event)\'><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u566.png" alt="u566"></div>\n          <input type="hidden" class="yuqi_check_line_id" id=\'yuqi_check_line_id_' +
        item.cinv_see_id +
        "' name=\"yuqi_check_line_id\" value='" +
        item.cinv_see_id +
        "'>\n          <input form='hidden_color_placeholder' class='zhengxin_check_color' id=\"yuqi_check_" +
        item.cinv_see_id +
        '" type="hidden" name="color" value="' +
        item.cinv_see_color +
        "\" />\n        </div>\n        <script>\n          $('#yuqi_check_" +
        item.cinv_see_id +
        "').colorPicker()\n          $('#yuqi_check_count_cycle_" +
        item.cinv_see_id +
        "').val('" +
        item.yuqi_check_count_cycle +
        "')\n          $('#yuqi_check_count_method_" +
        item.cinv_see_id +
        "').val('" +
        item.yuqi_check_count_method +
        "')\n          $('#yuqi_check_count_time_" +
        item.cinv_see_id +
        "').val('" +
        item.yuqi_check_count_time +
        "')\n          $('#yuqi_check_count_source_" +
        item.cinv_see_id +
        "').val('" +
        item.yuqi_check_count_source +
        "')\n        </script>\n      ").trim();
      $(".yuqi_check_box").append(templ);
    }
  });
}
